package client.comm.baoding.adapter.main

import android.content.Context
import android.content.Intent
import android.view.ViewGroup
import androidx.databinding.DataBindingUtil
import androidx.databinding.ViewDataBinding
import androidx.recyclerview.widget.RecyclerView
import client.comm.baoding.R
import client.comm.baoding.api.bean.CateGoods
import client.comm.baoding.api.bean.GoodsIndex
import client.comm.baoding.api.bean.TradeIndex
import client.comm.baoding.databinding.CateChildBigTagBinding
import client.comm.commlib.base.BaseAdapter
import client.comm.commlib.base.BindingViewHoder
import com.bumptech.glide.RequestManager
import com.bumptech.glide.load.engine.DiskCacheStrategy
import com.bumptech.glide.request.RequestOptions
import com.google.gson.Gson

class CateShowAdapter : BaseAdapter<CateGoods.TypeInfo> {

    fun itemClick(bean: CateGoods.TypeInfo, p: Int) {
//        context.startActivity(Intent(context, JyCateListActivity::class.java).apply {
//            putExtra("bean", bean)
//        })
        currIndex = p
        notifyDataSetChanged()
        cateCli?.invoke(bean, p)
    }

    var cateCli: ((CateGoods.TypeInfo, Int) -> Unit)? = null

    val manager: RequestManager

    var currIndex = 0

    constructor(context: Context, manager: RequestManager) : super(context) {
        this.manager = manager
    }
    //设置商品label标签

    override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): RecyclerView.ViewHolder {
        return BindingViewHoder(
            DataBindingUtil.inflate(
                layoutInflater,
                R.layout.cate_child_big_tag,
                parent,
                false
            )
        )
    }

    override fun onBindViewHolder(holder: RecyclerView.ViewHolder, position: Int) {
        val bindingViewHolder = holder as BindingViewHoder<ViewDataBinding>
        val binding = bindingViewHolder.binding as CateChildBigTagBinding
        val bean = getItem(position)

        binding.bean = bean
        binding.currIndex = position

        binding.txt.isSelected = position == currIndex

        binding.event = this
    }

}